// wenshidu/xiaonxq/xiaonxq.js
let app = getApp()
let yuming = app.globalData.yuming
var shuzong = []
var shu = []
const request = require('../../config/request');
Page({
  ...request,
  /**
   * 页面的初始数据
   */
  data: {
    yuming: yuming,
    title: '销售记录',
    xq: '',
    batch_number: '', //批号
    number_drugs: '', //药品编号
    page: 1,
    state: '',
    wu: false,
    istime: false,
    date: '开始时间', //开始
    endTime: '结束时间',
    starTime: '',
    endTimes: '',
    ku_bot_gao: '',
    kubxa_gao:''
  },
  // 选择开始时间
  bindDateChange: function (e) {
    this.setData({
      date: e.detail.value,
      starTime: e.detail.value
    })
    // 进销存
    // if (this.data.state == 0) {
      this.cunxq()
    // }
    // 冷链监测
    // if (this.data.state == 1) {
    //   this.lengxq()
    // }
  },
  // 选择结束时间
  endTime: function (e) {
    this.setData({
      endTime: e.detail.value,
      endTimes: e.detail.value,
    })
    // 进销存
    // if (this.data.state == 0) {
      this.cunxq()
    // }
    // 冷链监测
    // if (this.data.state == 1) {
    //   this.lengxq()
    // }
  },
  // 查看更多
  lookmore() {
    shuzong = this.data.xiaoshoxq
    this.setData({
      page: (this.data.page) + 1
    })
    // 进销存
    // if (this.data.state == 0) {
      // console.log(11111111)
      this.cunxq()
    // }
    // 冷链监测
    // if (this.data.state == 1) {
    //   console.log(222222)
    //   this.lengxq()
    // }
  },
  // 返回
  backs() {
    wx.navigateBack({
      delta: 0
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      heights: wx.getMenuButtonBoundingClientRect().top + 5,
      xq: wx.getStorageSync('gongying_xq'),
      batch_number: options.bian,
      number_drugs: options.drugs,
      state: options.state,
      ku_bot_gao: wx.getMenuButtonBoundingClientRect().top + 150,
      kubxa_gao:wx.getMenuButtonBoundingClientRect().top + 250,
    })
    // 进销存
    // if (options.state == 0) {
      // console.log(11111111)
      this.cunxq()
    // }
    // 冷链监测
    // if (options.state == 1) {
    //   console.log(222222)
    //   this.lengxq()
    // }
  },
  chongzhi(){
    this.setData({
      date:'开始时间',
      starTime:'',
      endTime:'结束时间',
      endTimes:'',
    })
    this.cunxq()
  },
  cunxq() {
    this.myRequest(yuming + 'Shop/shop_cheaout_xslogs', {
      shopId: wx.getStorageSync('shopId'),
      batch_number: this.data.batch_number,
      number_drugs: this.data.number_drugs,
      page: this.data.page,
      satrtime: this.data.starTime,
      endtime: this.data.endTimes
    }, "POST").then(res => {
      var shu = res.data.data;
      console.log(shu)
      if (this.data.page != 1) {
        if (shu.length != 10) {
          wx.showToast({
            title: '没有更多数据了~',
            icon: "none"
          })
          if (this.data.currtab == 0) {
            this.setData({
              wu: true
            })
          }
        }
      }
      this.setData({
        xiaoshoxq: shuzong.concat(shu)
      })
    })
  },
  lengxq() {
    this.myRequest(yuming + 'Shop/shop_jcckc_xslogs', {
      shopId: wx.getStorageSync('shopId'),
      number_drugs: this.data.number_drugs,
      page: this.data.page
    }, "POST").then(res => {
      this.setData({
        xiaoshoxq: res.data.data
      })
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },
})